package avaliacao.DAO;

import java.sql.Connection;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DAO {

    private DataSource ds;
    private final String database = "DB_MEC_ARCU_SUR";

    public DAO() {
        try {
            InitialContext ctx = new InitialContext();

            if (ctx == null) {
                System.out.println("[DAO.constructor] Falha no InitialContext.");
            }
          
            ds = (DataSource) ctx.lookup("java:comp/env/jdbc/"+database);
        }
        catch (Exception e) {
            System.out.println("[DAO.constructor] Excessão: " + e.getMessage());
        }
    }
//------------------------------------------------------------------------------------------------------------
    public Connection getConnection(){
        try{
            return ds.getConnection();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
}